package nc.ui.bd.mes.dmoys.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.LayoutManager;
import javax.swing.JPanel;
import nc.ui.pub.beans.UIButton;
import nc.ui.pub.beans.UIPanel;

public class DialogPanel extends UIPanel {
	private JPanel contentPnl;
	private LayoutManager layout;
	private UIButton[] boH;
	private UIButton[] boV;
	private UIButton[] topBtns = null;

	private UIButton[] bottomBtns = null;

	private static final int BTNWIDTH_STEP = 20;

	public static void main(String[] args) {
	}

//	//@Deprecated
//	public DialogPanel(JPanel contentPnl, UIButton[] hbos) {
//		this(contentPnl, hbos, null);
//	}
//
//	@Deprecated
//	public DialogPanel(JPanel contentPnl, UIButton[] hbos, UIButton[] vbos) {
//		this.contentPnl = contentPnl;
//		boH = hbos;
//		boV = vbos;
//		init();
//	}

	public DialogPanel(JPanel contentPnl, UIButton[] topBtns,
			UIButton[] bottomBtns, boolean bUseNewConstructor) {
		this.contentPnl = contentPnl;
		if (!bUseNewConstructor) {
			boH = topBtns;
			boV = bottomBtns;
			init();
		} else {
			this.topBtns = topBtns;
			this.bottomBtns = bottomBtns;
			init4V6();
		}
	}

	private void init4V6() {
		layout = new BorderLayout();
		setLayout(layout);
		ButtonPanel topBtnPnl = null;
		ButtonPanel bottomBtnPnl = null;

		if (topBtns != null) {
			topBtnPnl = new ButtonPanel(topBtns, 0, true);
			int height = topBtns[0].getHeight();
			for (int i = 0; i < topBtns.length; i++) {
				height = Math.max(height, topBtns[i].getHeight());
			}
			height += 20;
			topBtnPnl.setPreferredSize(new Dimension(getWidth(), height));
		}
		if (bottomBtns != null) {
			bottomBtnPnl = new ButtonPanel(bottomBtns, 0, false);
			int height = bottomBtns[0].getHeight();
			for (int i = 0; i < bottomBtns.length; i++) {
				height = Math.max(height, bottomBtns[i].getHeight());
			}
			height += 20;
			bottomBtnPnl.setPreferredSize(new Dimension(getWidth(), height));
		}

		add(contentPnl, "Center");
		if (topBtnPnl != null) {
			add(topBtnPnl, "North");
		}
		if (bottomBtnPnl != null) {
			add(bottomBtnPnl, "South");
		}
	}

	private void init() {
		setLayout(new BorderLayout());
		ButtonPanel vBpnl = null;
		ButtonPanel hBpnl = null;
		if (boV != null) {
			vBpnl = new ButtonPanel(boV, 1, false);
			int width = boV[0].getWidth();
			for (int i = 0; i < boV.length; i++) {
				width = Math.max(width, boV[i].getWidth());
			}
			width += 20;
			vBpnl.setPreferredSize(new Dimension(width + 20, getHeight()));
		}
		if (boH != null) {
			hBpnl = new ButtonPanel(boH, 0, false);
			int height = boH[0].getHeight();
			for (int i = 0; i < boH.length; i++) {
				height = Math.max(height, boH[i].getHeight());
			}
			height += 20;
			hBpnl.setPreferredSize(new Dimension(getWidth(), height));
		}
		add(contentPnl, "Center");
		if (vBpnl != null) {
			add(vBpnl, "East");
		}
		if (hBpnl != null) {
			add(hBpnl, "South");
		}
	}
}
